import { Form } from 'antd';
import React, { FC, useEffect } from 'react';
import { renderItem } from '@/utils/common';
import { fenToYuan } from '@/utils/utils';
import { createFields } from './fields';

interface AdvancedFormProps { }

const CreateGoods: FC<AdvancedFormProps> = (props: any) => {
  const { form, detail } = props;

  const { setFieldsValue } = form;

  useEffect(() => {
    const toData = fenToYuan(detail, ['cost_price', 'market_price', 'price']);
    setFieldsValue(toData);
  }, [detail]);


  const layout = {
    labelCol: { span: 4 },
    wrapperCol: { span: 20 },
  };

  return (
    <Form
      style={{ width: 600 }}
      {...layout}
      form={form}
      layout="horizontal"
      initialValues={detail}
    >
      {
        createFields.map(it => renderItem(it, detail))
      }
    </Form>
  );
};

export default CreateGoods;
